package com.qf.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qf.mapper.SetmealMapper;
import com.qf.pojo.Setmeal;
import com.qf.service.SetmealService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class SetmealServiceImpl extends ServiceImpl<SetmealMapper, Setmeal> implements SetmealService {

    @Autowired
    private SetmealMapper setmealMapper;

    @Transactional(rollbackFor = Exception.class)
    @Override
    public int saveSetmeal(Setmeal setmeal, String ... checkgroupIds) {

        //向setmeal表中添加一条记录
        setmealMapper.insert(setmeal);

        //向setmeal和checkgroup表的中间表中添加记录
        for (String checkgroupId : checkgroupIds) {
            setmealMapper.insertSetmealAndCheckgroup(setmeal.getId(),checkgroupId);
        }

        return 1;
    }
}
